import 'package:flutter/material.dart';

//Flutter 富文本
void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  //当前显示 的页面
  int _currentIndex = 0;
  @override
  Widget build(BuildContext context) {
    //脚手架
    return Scaffold(
      appBar: AppBar(
        title: Text('标题'),
        backgroundColor: Colors.blue,
        foregroundColor: Colors.white,
      ),

      body: buildBody(),

      bottomNavigationBar: BottomNavigationBar(
        //当前显示  激活的索引
        currentIndex: _currentIndex,
        //
        onTap: (int index) {
          setState(() {
            _currentIndex = index;
          });
        },
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
          BottomNavigationBarItem(icon: Icon(Icons.bubble_chart), label: '发现'),
          BottomNavigationBarItem(icon: Icon(Icons.person), label: '我的'),
        ],

        //选中的颜色
        //fixedColor: Colors.red,
        selectedItemColor: Colors.orange,
        //未选中的颜色
        unselectedItemColor: Colors.grey,
        //图标大小
        iconSize: 33,
        //
        selectedLabelStyle: TextStyle(
          fontSize: 18,
          fontWeight: FontWeight.bold,
        ),
        unselectedLabelStyle: TextStyle(
          fontSize: 16,
          fontWeight: FontWeight.normal,
        ),
        //是否展示 未选中的标签的文本
        showUnselectedLabels: true,
      ),

      // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  Widget buildBody() {
    if (_currentIndex == 0) {
      return HomePage();
    }
    if (_currentIndex == 1) {
      return ShopPage();
    }
    return PersonPage();
  }
}

//定义 三个页面
class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(child: Text('首页面'));
  }
}

class ShopPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(child: Text('发现'));
  }
}

class PersonPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(child: Text('我的页面'));
  }
}
